﻿using System;
using System.Web;
using System.Web.UI;
using MyHealthByDesign.Helper;

namespace MyHealthByDesign
{
    /// <summary>
    /// Description:
    /// Displays forgot password page
    /// 
    /// Author: Sanjeev Shrestha
    /// Date Created: 10/17/2011
    /// 
    /// Other code files referenced:
    /// None.
    /// 
    /// Regression Test Information:
    /// None.
    /// 
    /// Revision History:
    /// 10/20/2011 Sanjeev Shrestha - change logic for user id.
    /// 
    /// Known Faults:
    /// None.
    /// </summary>
    public partial class ForgotPassword : System.Web.UI.Page
    {
        Domain.Domain domain = new Domain.Domain();

        /// <summary>
        ///  Page Load event handler 
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// None
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Submit button event handler - send mail
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Mail sent
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string email = txtEmail.Text;

            if(domain.SendEmail(email))
            {
                txtEmail.Visible = false;
                btnSubmit.Visible = false;
                lblEmail.Visible = false;
                lblRequired.Visible = false;
                lblSuccess.Visible = true;
                hplnkLogin.Visible = true;
            }
            else
            {
                DisplayErrorMessage("Error! Could not find password for entered email address!");
            }
        }

        /// <summary>
        /// DisplayErrorMessage - displays error if needed 
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Error is displayed if necessary
        /// </summary>
        /// <param name="message"></param>
        public static void DisplayErrorMessage(string message)
        {
            var currentPage = HttpContext.Current.Handler as Page;
            if (currentPage != null) currentPage.Validators.Add(new ValidationError(message));
        }
    }
}